package com.zhy.baselibrary.utils.span;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.style.ReplacementSpan;

public class BackgroundSpan extends ReplacementSpan {
    private Bitmap bitmap;
 
    public BackgroundSpan(Bitmap bitmap) {
        this.bitmap = bitmap;
    }
 
    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
        return bitmap.getWidth(); // 返回背景图片的宽度
    }
 
    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        canvas.drawBitmap(bitmap, x, y, paint); // 在指定位置绘制背景图片
        // 如果需要，可以在此处绘制文本
    }
}